home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH6 / SRC / CIRCLE3.FRM < prev    next >
Text File  |  1996-05-01  |  6KB  |  227 lines

  1. VERSION 4.00
  2. Begin VB.Form CircleForm 
  3.    Caption         =   "Circle 3"
  4.    ClientHeight    =   5670
  5.    ClientLeft      =   2085
  6.    ClientTop       =   735
  7.    ClientWidth     =   4830
  8.    Height          =   6360
  9.    Left            =   2025
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   378
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   322
  14.    Top             =   105
  15.    Width           =   4950
  16.    Begin VB.TextBox ThetaText 
  17.       Height          =   285
  18.       Left            =   4200
  19.       TabIndex        =   11
  20.       Text            =   "30"
  21.       Top             =   480
  22.       Width           =   615
  23.    End
  24.    Begin VB.TextBox YscaleText 
  25.       Height          =   285
  26.       Left            =   2160
  27.       TabIndex        =   9
  28.       Text            =   "0.5"
  29.       Top             =   480
  30.       Width           =   615
  31.    End
  32.    Begin VB.TextBox XscaleText 
  33.       Height          =   285
  34.       Left            =   600
  35.       TabIndex        =   7
  36.       Text            =   "1.0"
  37.       Top             =   480
  38.       Width           =   615
  39.    End
  40.    Begin VB.TextBox DtText 
  41.       Height          =   285
  42.       Left            =   2160
  43.       TabIndex        =   6
  44.       Text            =   "0.1"
  45.       Top             =   45
  46.       Width           =   615
  47.    End
  48.    Begin VB.TextBox TminText 
  49.       Height          =   285
  50.       Left            =   0
  51.       TabIndex        =   4
  52.       Text            =   "0"
  53.       Top             =   45
  54.       Width           =   615
  55.    End
  56.    Begin VB.CommandButton CmdGo 
  57.       Caption         =   "Go"
  58.       Default         =   -1  'True
  59.       Height          =   375
  60.       Left            =   4200
  61.       TabIndex        =   3
  62.       Top             =   0
  63.       Width           =   615
  64.    End
  65.    Begin VB.TextBox TmaxText 
  66.       Height          =   285
  67.       Left            =   1200
  68.       TabIndex        =   2
  69.       Text            =   "6.2832"
  70.       Top             =   45
  71.       Width           =   615
  72.    End
  73.    Begin VB.PictureBox Canvas 
  74.       AutoRedraw      =   -1  'True
  75.       Height          =   4815
  76.       Left            =   0
  77.       ScaleHeight     =   -2.2
  78.       ScaleLeft       =   -1.1
  79.       ScaleMode       =   0  'User
  80.       ScaleTop        =   1.1
  81.       ScaleWidth      =   2.2
  82.       TabIndex        =   0
  83.       Top             =   840
  84.       Width           =   4815
  85.    End
  86.    Begin VB.Label Label1 
  87.       Caption         =   "Angle (degrees)"
  88.       Height          =   255
  89.       Index           =   5
  90.       Left            =   3000
  91.       TabIndex        =   12
  92.       Top             =   525
  93.       Width           =   1215
  94.    End
  95.    Begin VB.Label Label1 
  96.       Caption         =   "Y scale"
  97.       Height          =   255
  98.       Index           =   3
  99.       Left            =   1560
  100.       TabIndex        =   10
  101.       Top             =   525
  102.       Width           =   615
  103.    End
  104.    Begin VB.Label Label1 
  105.       Caption         =   "X scale"
  106.       Height          =   255
  107.       Index           =   2
  108.       Left            =   0
  109.       TabIndex        =   8
  110.       Top             =   525
  111.       Width           =   615
  112.    End
  113.    Begin VB.Label Label1 
  114.       Caption         =   "dt"
  115.       Height          =   255
  116.       Index           =   1
  117.       Left            =   1920
  118.       TabIndex        =   5
  119.       Top             =   60
  120.       Width           =   255
  121.    End
  122.    Begin VB.Label Label1 
  123.       Caption         =   "<= t <="
  124.       Height          =   255
  125.       Index           =   0
  126.       Left            =   645
  127.       TabIndex        =   1
  128.       Top             =   60
  129.       Width           =   495
  130.    End
  131.    Begin VB.Menu mnuFile 
  132.       Caption         =   "&File"
  133.       Begin VB.Menu mnuFileExit 
  134.          Caption         =   "E&xit"
  135.       End
  136.    End
  137. End
  138. Attribute VB_Name = "CircleForm"
  139. Attribute VB_Creatable = False
  140. Attribute VB_Exposed = False
  141. Option Explicit
  142.  
  143. Const PI = 3.14159
  144.  
  145.  
  146. ' ************************************************
  147. ' Draw the curve on the indicated picture box.
  148. ' ************************************************
  149. Sub DrawCurve(pic As PictureBox, start_t As Single, stop_t As Single, dt As Single, xscale As Single, yscale As Single, theta As Single)
  150. Dim x1 As Single
  151. Dim y1 As Single
  152. Dim x2 As Single
  153. Dim y2 As Single
  154. Dim ctheta As Single
  155. Dim stheta As Single
  156. Dim t As Single
  157.  
  158.     ' Save these values because we use them a lot.
  159.     stheta = Sin(theta)
  160.     ctheta = Cos(theta)
  161.     
  162.     x1 = xscale * X(start_t)
  163.     y1 = yscale * Y(start_t)
  164.     x2 = x1 * ctheta - y1 * stheta
  165.     y2 = x1 * stheta + y1 * ctheta
  166.     pic.Cls
  167.     pic.CurrentX = x2
  168.     pic.CurrentY = y2
  169.     
  170.     t = start_t + dt
  171.     Do While t < stop_t
  172.         x1 = xscale * X(t)
  173.         y1 = yscale * Y(t)
  174.         x2 = x1 * ctheta - y1 * stheta
  175.         y2 = x1 * stheta + y1 * ctheta
  176.         pic.Line -(x2, y2)
  177.         t = t + dt
  178.     Loop
  179.     
  180.     x1 = xscale * X(stop_t)
  181.     y1 = yscale * Y(stop_t)
  182.     x2 = x1 * ctheta - y1 * stheta
  183.     y2 = x1 * stheta + y1 * ctheta
  184.     pic.Line -(x2, y2)
  185. End Sub
  186.  
  187.  
  188.  
  189. ' ************************************************
  190. ' The parametric function Y(t).
  191. ' ************************************************
  192. Function Y(t As Single) As Single
  193.     Y = Sin(t)
  194. End Function
  195.  
  196. ' ************************************************
  197. ' The parametric function X(t).
  198. ' ************************************************
  199. Function X(t As Single) As Single
  200.     X = Cos(t)
  201. End Function
  202.  
  203. Private Sub CmdGo_Click()
  204. Dim tmin As Single
  205. Dim tmax As Single
  206. Dim dt As Single
  207. Dim xscale As Single
  208. Dim yscale As Single
  209. Dim theta As Single
  210.  
  211.     tmin = CSng(TminText.Text)
  212.     tmax = CSng(TmaxText.Text)
  213.     dt = CSng(DtText.Text)
  214.     xscale = CSng(XscaleText.Text)
  215.     yscale = CSng(YscaleText.Text)
  216.     theta = CSng(ThetaText.Text) / 180 * PI
  217.     DrawCurve Canvas, tmin, tmax, dt, xscale, yscale, theta
  218. End Sub
  219.  
  220.  
  221. Private Sub mnuFileExit_Click()
  222.     Unload Me
  223. End Sub
  224.  
  225.  
  226.  
  227.